<template>
  <div>
    <div class="bar">
      <ul>
        <li @click="getList(null)">全部</li>
        <li @click="getList(0)">华语</li>
        <li @click="getList(96)">欧美</li>
        <li @click="getList(16)">韩国</li>
        <li @click="getList(8)">日本</li>
      </ul>
      <div>
        <span>播放全部</span>
        <span>收藏全部</span>
      </div>
    </div>
    <div class="contentlist">
      <ul>
        <li v-for="i in songList" :key="i.id" @click="play(i.id)">
          <div class="face">
            <img v-lazy="i.album.picUrl" alt="" /> {{ i.name }}
            <span v-if="i.alias.length" class="origin">({{ i.alias[0] }})</span>
          </div>
          <div class="author" @click.stop='toArtist(i.artists[0].id)'>{{ i.artists[0].name }}</div>
          <div class="title" >
            {{ i.name }}
            <span v-if="i.alias.length" class="origin">({{ i.alias[0] }})</span>
          </div>
          <div class="time">
            {{ getTime(i.duration) }}
          </div>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      songList: [],
    };
  },
  methods: {
    getList(type) {
     
        this.$request({
          url: "/top/song",
          params: {
            type: type,
          },
        }).then((success) => {
          this.songList = success.data.data;
        });
    },
    toArtist(id){
      this.$router.push({name:'zhuanji',query:{id:id}})
    },
    play(id){
      this.$store.state.mid=id
      this.$root.eventhub.$emit('play')
    }
  },
  computed: {
    getTime() {
      return function (time) {
        let min = Math.floor(time / 60000).toString()[1]
          ? Math.floor(time / 60000).toString()
          : "0" + Math.floor(time / 60000).toString();
        let sec = Math.floor(time % 60000)
          .toString()
          .slice(0, 2);
        return min + ":" + sec;
      };
    },
  },
  mounted() {
    this.$request({
      url: "/top/song",
    }).then((success) => {
      this.songList = success.data.data;
    });
  },
};
</script>

<style scoped>
.bar {
  display: flex;
  justify-content: space-between;
  margin-top: 20px;
}
.bar ul {
  display: flex;
}
.bar ul li {
  margin: 0 20px;
  line-height: 30px;
}

.bar div span {
  display: inline-block;
  border: 1px solid #ccc;
  text-align: center;
  margin-left: 10px;
  width: 100px;
  height: 30px;
  line-height: 30px;
  border-radius: 15px;
}
.contentlist {
  margin-top: 20px;
}
.contentlist ul li {
  display: flex;
  align-items: center;
  padding: 10px;
  height: 100px;
}
.contentlist ul li img {
  height: 80px;
  vertical-align: middle;
  border-radius: 10px;
  margin-right: 10px;
}
.contentlist ul li:nth-child(2n) {
  background-color: #f6f6f7;
}
.contentlist ul li:hover {
  background-color: rgb(241, 241, 241);
}
.origin {
  font-size: 14px;
  color: #ccc;
}
.face {
  width: 400px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.author {
  width: 200px;
}
.author:hover{
  font-size: 17px;
}
.title {
  width: 200px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  margin-right: 40px;
  font-size: 14px;
  color: #ccc;
}
.time {
  font-size: 14px;
  color: gray;
}
</style>